//
//  RecView.m
//  HappyTrip
//
//  Created by GeminyXC on 15-4-4.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "RecView.h"
#import "DateBaseHandler.h"
#import "TravelNoteViewController.h"

@implementation RecView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)dealloc
{
    [_noteArr release];
    [_tableView release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor redColor];
       
        self.noteArr = [NSMutableArray array];
        
        self.tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
        self.tableView.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self addSubview:self.tableView];
        [_tableView release];
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
        //
//        self.noteArr = [[DateBaseHandler shareInstance] selectAll];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

//    self.noteArr = [[DateBaseHandler shareInstance] selectAll];

   
//    NSLog(@"===================%@", [self.noteArr[0] idNumber]);


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    self.noteArr = [[DateBaseHandler shareInstance] selectAll];
    NSLog(@"!!!!!!!!!++++++++++!!!!!!!!!!!!!-------------");
    if (0 == self.noteArr.count) {
        [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        self.tableView.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"collect.png"]] autorelease];
    }else
    {
        self.tableView.backgroundView = nil;
        [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
    }
    return self.noteArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.textLabel.text = [[self.noteArr objectAtIndex:indexPath.row] name];
    cell.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TravelNoteViewController *travVC = [[TravelNoteViewController alloc] init];
//    NoteCollect *note = [self.noteArr objectAtIndex:indexPath.row];
//    NSString *str = note.idNumber;
//    NSLog(@"---------%@", str);
      travVC.transmitId = [[self.noteArr objectAtIndex:indexPath.row] idNumber];//*****
//    NSLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!+++++++++%@", [[self.noteArr objectAtIndex:indexPath.row] idNumber]);
    NSLog(@"%@", [self.noteArr[0] idNumber]);
    [self.target pushViewController:travVC animated:YES];
    [travVC release];
}







@end
